package com.nd.android.musicboxlibrary.util.fastDateUtil;

import com.nd.android.musicboxlibrary.business.comm.MagicNumber;

import java.util.Calendar;

/**
 * <p>
 * Inner class to output a two digit month.
 * </p>
 */
public class TwoDigitMonthField implements NumberRule {
    public static final TwoDigitMonthField INSTANCE = new TwoDigitMonthField();

    /**
     * Constructs an instance of <code>TwoDigitMonthField</code>.
     */
    public TwoDigitMonthField() {
        super();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int estimateLength() {
        return 2;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void appendTo(StringBuffer buffer, Calendar calendar) {
        appendTo(buffer, calendar.get(Calendar.MONTH) + 1);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final void appendTo(StringBuffer buffer, int value) {
        buffer.append((char) (value / MagicNumber.n10 + '0'));
        buffer.append((char) (value % MagicNumber.n10 + '0'));
    }
}
